﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using CastleDefender.Platform.ScreenBehavior;
using Microsoft.Xna.Framework.Graphics;
using CastleDefender.ConfigFolder;
using CastleDefender.Object;

namespace CastleDefender.Platform.GameScene
{
    public abstract class GameInfo : GameScene
    {
        #region VARIABLE

        private bool blnBack;
        private Button btnBack;
        private TouchBehavior tbTouch;

        #endregion

        #region CONSTRUCTOR
        public GameInfo(Game myGame, ref TouchBehavior touch, string nameScene)
            : base(myGame, Config.FolderBackgrounds + nameScene)
        {
            blnBack = false;
            tbTouch = touch;

            //Load hình ảnh nút bấm
            Texture2D textureBack = myGame.Content.Load<Texture2D>(Config.FolderButtons + "Back");
            btnBack = new Button(myGame, ref textureBack, 40, 40, true, false, Vector2.Zero);
            Components.Add(btnBack);
        }

        #endregion

        #region PUBLIC METHOD

        public override void Show()
        {
            blnBack = false;
            base.Show();
        }

        public override void Hide()
        {
         
            base.Hide();
        }

        public override void Update(GameTime gameTime)
        {
            if (Enabled && Visible)
            {
                UpdateButton();
                base.Update(gameTime);
            }
        }

        #endregion

        #region PRIVATE METHOD

        //Cập nhật sự kiên nút bấm
        private void UpdateButton()
        {
            if (tbTouch.IsMoved || tbTouch.IsPressed)
            {
                Point pos = new Point((int)tbTouch.PosCurrent.X, (int)tbTouch.PosCurrent.Y);
                btnBack.GetTouchPosition(pos);

                if (btnBack.Touch)
                {
                    btnBack.Active = true;
                }
                else
                {
                    btnBack.Active = false;
                }
             
            }

            //Thực hiện trở về trang trước
            if (tbTouch.IsKeyUp && btnBack.Touch)
            {
                blnBack = true;

                //Tắt nút bấm khi đã thực thi
                btnBack.Active = false;
                btnBack.GetTouchPosition(new Point(100, 100));
            }
        }

        #endregion

        #region PUBLIC PROPERTIES

        //Nhận trả giá trị blnBack
        public bool Back
        {
            get { return blnBack; }
            private set { }
        }

        #endregion

    }
}
